//
//  ModuleBViewController.swift
//  NCRouterBus
//
//  Created by zhanwenyan on 2018/10/17.
//  Copyright © 2018年 Newcoretech. All rights reserved.
//

import UIKit

class ModuleBViewController: UIViewController, NCModuleRouterController {
    static func `init`(params: [String : Any]?, onResult: (([String : Any]?) -> Void)?, isPresent: Bool) -> UIViewController? {
        let vc = ModuleBViewController()
        vc.isPresent = isPresent
        vc.onResult = onResult
        return vc
    }
    
    var onResult: (([String : Any]?) -> Void)?
    
   
//    static func initWith(params: NSDictionary?, onResult: ((NSDictionary?) -> Void)?, isPresent: Bool) -> UIViewController {
//        let vc = ModuleBViewController()
//        vc.isPresent = isPresent
//        vc.onResult = onResult
//        return vc
//    }
    
//    var onResult: ((NSDictionary?) -> Void)?
    
    var isPresent: Bool = false
    
    @IBOutlet weak var resultLb: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "ModuleB"
    }
    @IBAction func didPushModuleA(_ sender: Any) {
        let params: [String: Any] = ["name": "ModuleBViewController", "info": 200]
//        let p = NSDictionary(dictionaryLiteral: ("name", "ModuleBViewController"), ("info", 300))
        
        NCModuleRouterBus.route(to: URL(string: "ModuleA://page/ModuleAViewController"), vc: self, skipType: .push(animated: true), params: params) { res in
            self.resultLb.text = res?["result"] as? String
        }
//        NCModuleRouterBus.routeTo(url: NSURL(string: "ModuleA://page/ModuleAViewController"), nc: navigationController!, params: p, onResult: { (res: NSDictionary?) in
//            self.resultLb.text = res?.value(forKey: "result") as? String ?? "none"
//        }, isPresent: false)
    }

    @IBAction func didDismiss(_ sender: Any) {
        if(isPresent){
            dismiss(animated: true, completion: nil)
        }else{
            navigationController?.popViewController(animated: true)
        }
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
